#ifndef _LUA_HTTP_H__
#define _LUA_HTTP_H__
#include "Script.h"
#include "Lock.h"
#include <string>


typedef std::map<int, std::string> StringMap;

class CLuaHttp: public CScriptInterface
{
public:
	CLuaHttp(void);
	~CLuaHttp(void);
	static CLuaHttp& Instance();
	virtual bool Init(lua_State* L, const char* name);
	virtual bool UnRegisterObject();
	void Update();
	void Stop();
	void search();
protected:
	static int httpGet(lua_State* L);
	static int utf8(lua_State* L);
	static int gbk32(lua_State* L);
	std::string OnHttpGet( std::string url);
	static unsigned int WINAPI ThreadFunc( void* pArguments );
	void run(int id);
	void pushString(int id, std::string& str);
	static std::string U2G(const char* utf8);
	static std::string G2U(const char* gb2312);
private:
	CLock			m_lock;
	bool			m_start;
	StringMap		m_urls;
	StringMap		m_strings;
};


#endif
